#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

namespace F { // max_flow_with_cost
    const int N = 210;
    const int M = N * N;
    const int inf = 0x3f3f3f3f;
    int h[N],cnt = 1,S,T,pre[N],incf[N];
    bool vis[N];
    ll maxflow,cost,dis[N];
    struct edge { int v,w; ll c; int nxt; } e[M << 1];
    inline void tlink(int x,int y,int w,ll c) { e[++cnt] = (edge) { y,w,c,h[x] }; h[x] = cnt; }
    inline void link(int x,int y,int w,ll c) { tlink(x,y,w,c); tlink(y,x,0,-c); }
    inline void setst(int s,int t) { S = s; T = t; }
    bool bfs() {
	queue < int > q; q.push(S); memset(dis,0xcf,sizeof dis); memset(vis,0,sizeof vis); dis[S] = 0; vis[S] = 1;
	incf[S] = inf;
	while(!q.empty()) {
	    int x = q.front(); q.pop();
	    for(int i = h[x],y;i;i = e[i].nxt)
		if(e[i].w && dis[y = e[i].v] < dis[x] + e[i].c) {
		    dis[y] = dis[x] + e[i].c; pre[y] = i; incf[y] = min(e[i].w,incf[x]);
		    if(!vis[y]) vis[y] = 1,q.push(y);
		}
	    vis[x] = 0;
	} return dis[T] >= -cost;
    }
    bool update() {
	int x = T;
	if(incf[T] * dis[T] + cost >= 0) {
	    while(x ^ S) {
		int i = pre[x]; e[i].w -= incf[T]; e[i ^ 1].w += incf[T];
		x = e[i ^ 1].v;
	    }
	    cost += incf[T] * dis[T]; maxflow += incf[T]; return true;
	} else return maxflow += -cost / dis[T],false;
    }
    void runit() { while(bfs() && update()); }
};

const int N = 210;
const int L = 1e5 + 10;

int n;
int a[N],b[N],c[N],col[N];
bool v[L];
int pri[L],pnum;

void shai(int l) {
    for(int i = 2;i <= l;i++) {
	if(!v[i]) pri[++pnum] = i;
	for(int j = 1;j <= pnum && pri[j] * i <= l;j++) {
	    v[pri[j] * i] = 1; if(i % pri[j] == 0) break;
	}
    }
}

int getpr(int x) {
    int cnt = 0;
    for(int i = 1;i <= pnum && (ll) pri[i] * pri[i] <= x;i++) {
	while(x % pri[i] == 0) cnt++,x /= pri[i];
    }
    if(x > 1) cnt++;
    return cnt;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in; for(int i = 1;i <= n;i++) a[i] = in;
    for(int i = 1;i <= n;i++) b[i] = in;
    for(int i = 1;i <= n;i++) c[i] = in;
    F :: setst(0,n + 1); shai(100000);
    for(int i = 1;i <= n;i++) col[i] = getpr(a[i]);
    vec pot[2];
    for(int i = 1;i <= n;i++) pot[col[i] & 1].pb(i);
    for(auto x : pot[0]) {
	for(auto y : pot[1])
	    if((a[y] % a[x] == 0 && col[y] == col[x] + 1) || (a[x] % a[y] == 0 && col[x] == col[y] + 1))
		F :: link(x,y,F :: inf,(ll)c[x] * c[y]);
    }
    for(auto x : pot[0]) F :: link(0,x,b[x],0); for(auto y : pot[1]) F :: link(y,n + 1,b[y],0);
    F :: runit(); printf("%lld\n",F :: maxflow); return 0;
}
